package com.example.wisdomclassroomapi.domain.repository;

import com.example.wisdomclassroomapi.domain.entity.ScheduleOutlineEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.ScheduleOutlineMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-26
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-26
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class ScheduleOutlineRepository {
    @Resource
    private ScheduleOutlineMapper scheduleOutlineMapper;

    public void add(ScheduleOutlineEntity entity) {
       scheduleOutlineMapper.insert(entity);
    }

    public ScheduleOutlineEntity findById(String id) {
        return scheduleOutlineMapper.selectById(id);
    }

    public int updateById(ScheduleOutlineEntity entity) {
        return scheduleOutlineMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return scheduleOutlineMapper.deleteById(id);
    }

    public IPage<ScheduleOutlineEntity> page(ScheduleOutlineEntity entity,IPage page) {
        QueryWrapper<ScheduleOutlineEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getName())){
            wrapper.eq("name",entity.getName());
            }
            if (StringUtils.isNotBlank(entity.getMajorId())){
            wrapper.eq("major_id",entity.getMajorId());
            }
            if (StringUtils.isNotBlank(entity.getSubjectId())){
            wrapper.eq("subject_id",entity.getSubjectId());
            }
            if (entity.getStartDate()!=null){
            wrapper.eq("start_date",entity.getStartDate());
            }
            if (entity.getEndDate()!=null){
            wrapper.eq("end_date",entity.getEndDate());
            }
        return scheduleOutlineMapper.selectPage(page, wrapper);
    }

    public List<ScheduleOutlineEntity> list(ScheduleOutlineEntity entity) {
        QueryWrapper<ScheduleOutlineEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getName())){
            wrapper.eq("name",entity.getName());
            }
            if (StringUtils.isNotBlank(entity.getMajorId())){
            wrapper.eq("major_id",entity.getMajorId());
            }
            if (StringUtils.isNotBlank(entity.getSubjectId())){
            wrapper.eq("subject_id",entity.getSubjectId());
            }
            if (entity.getStartDate()!=null){
                wrapper.eq("start_date",entity.getStartDate());
            }
            if (entity.getEndDate()!=null){
                wrapper.eq("end_date",entity.getEndDate());
            }
        return scheduleOutlineMapper.selectList(wrapper);
    }

}